- [Useful stuff](#org51cbb5c)
  - [Process explorer](#orgf758275)
  - [eshell -> clipboard](#org1f32074)
  - [run visual commands in eshell](#org5eafb23)
  - [eshell pipe support](#org581faea)
  - [all the shells](#org31edfa5)
  - [modify eshell prompt](#orgda5318d)
  - [inspect buffer variables](#org80fd82a)
  - [inspect variables](#orgcf591a6)
  - [inspect defined procedures](#orgf346d18)
  - [clear eshell](#org9189c71)
  - [font / face at point](#org209ba51)
  - [Library of Babel](#org4d3bc6f)
  - [Finding help inside Emacs](#org164f229)
  - [Font stuff](#org184df6b)



<a id="org51cbb5c"></a>

# Useful stuff


<a id="orgf758275"></a>

## Process explorer

M-x proced RET


<a id="org1f32074"></a>

## eshell -> clipboard

command > /dev/clip


<a id="org5eafb23"></a>

## run visual commands in eshell

some are already defined as visual, other are not, in which case you might want to add them:

```elisp
(add-to-list 'eshell-visual-commands "htop")
```

for example


<a id="org581faea"></a>

## eshell pipe support

```eshell
command | command
command >>> #<buffer name>
command > filename
```


<a id="org31edfa5"></a>

## all the shells

-   shell - bash / sh in Emacs
-   eshell - eshell
-   ielm - elisp REPL
-   term
-   ansi-term


<a id="orgda5318d"></a>

## modify eshell prompt

```elisp
(defun set-eshell-prompt-function ()
  (setq eshell-prompt-function
        (function
         (lambda ()
           (concat
            (propertize (format-time-string "%H:%M:%S" (current-time))
                        'face
                        `(:foreground "#A0A0A0"))
            "::"
            (propertize (user-login-name)
                        'face
                        `(:foreground "#FF9080"))
            "@"
            (propertize (let ((sys-name (system-name)))
                          (let ((sys-name-len (length sys-name)))
                            (if (> sys-name-len 8)
                                (concat (substring sys-name 0 8) "...")
                              sys-name)))
                        'face
                        `(:foreground "#FF9080"))
            "::"
            (propertize
             (let ((limit 36)
                   (loc
                    (if (string= (eshell/pwd) (getenv "HOME"))
                        "~"
                      (eshell/pwd))))
               (let ((loc-length (length loc)))
                 (if (> loc-length limit)
                     (concat "..." (substring loc (- loc-length limit)))
                   loc)))
             'face
             `(:foreground "#FF9080"))
            "$ "))))
  (setq eshell-highlight-prompt t)
  (setq eshell-prompt-regexp "^[^#$\n]*[#$] "))

(set-eshell-prompt-function)
```


<a id="org80fd82a"></a>

## inspect buffer variables

```emacs
M-x pp-eval-expression RET (buffer-local-variables) RET
```


### inspect editorconfig variables

```emacs
M-x pp-eval-expression RET editorconfig-properties-hash RET
```


<a id="orgcf591a6"></a>

## inspect variables

`C-h v` enter variable name `RET`


<a id="orgf346d18"></a>

## inspect defined procedures

-   `C-h f` for getting help about procedures
-   enter a procedure name
-   `RET`


<a id="org9189c71"></a>

## clear eshell

run `clear 1`


<a id="org209ba51"></a>

## font / face at point

`C-u C-x =`

or

`M-x describe-face RET`


<a id="org4d3bc6f"></a>

## Library of Babel

Library of Babel (LoB) allows you to define a function in any supported programming language and use it inside org documents. The following contains examples for usage of the LoB. (If you are viewing this document's markdown version, the following examples probably will not be completely visible, as there are org-mode elements, which have no equivalent in typical markdown dialects.)


### Ingest org files

In order to use functions defined in source blocks within other files, one needs to "ingest" them first, using either `M-x org-babel-lob-ingest` or default key binding `C-c C-v i`.


### Guile version

```scheme
(version)
```

    3.0.7


### Upcase string

```scheme
(define upcase
  (λ (str)
    (string-upcase str)))

(upcase input-str)
```

    TEST


### Timestamp calculation example

```scheme
(import
 (ice-9 format)
 (srfi srfi-19))


(define org-timestamp->time-utc
  (λ (timestamp-string)
    (let ([parsed-date (string->date timestamp-string "[~Y-~m-~d ~a ~H:~M]")])
          (date->time-utc parsed-date))))


(define duration->hours
  (λ (duration)
    ;; 1h = 60min = 3600s
    (/ (time-second duration) 3600)))


(define org-lob-timediff
  (λ (org-dt1 org-dt2)
    ;; formatting float:

    ;; ~@width, decimals, scale, overflowchar, padchar

    ;; ~ placeholder is following
    ;; @ with sign if negative
    ;; width: minimum width
    ;; decimals: minimum number of digits after decimal point
    ;; scale: ???
    ;; overflowchar: ???
    ;; padchar: char to use for padding
    (format #f
            "~,2f"
            (number->string
             (exact->inexact
              (duration->hours
               (time-difference (org-timestamp->time-utc org-dt2)
                                (org-timestamp->time-utc org-dt1))))))))


(org-lob-timediff dt1 dt2)
```


<a id="org164f229"></a>

## Finding help inside Emacs


### Key bindings

Usually you can use `C-h k` for "help about key". Emacs will then query for the key combination, which you want help for. Sometimes however the key combination is bound by the system's window manager for example and this will prevent Emacs to receive your key combination, which means you cannot answer its query with that key combination. In such cases you can use the following way of getting help:

```elisp
(describe-key (kbd "M-TAB"))
```


<a id="org184df6b"></a>

## Font stuff


### set default font

Put the following in your `init.el` file:

```elisp
(let ((standard-font "DejaVu Sans Mono:weight=normal:height=110:antialias=1"))
  (set-frame-font standard-font))
```


### set charset or fontset font

This is useful when wanting to use a different font for characters of other languages, which might require a different font, like Chinese.

Put the following in your `init.el` file:

```elisp
;; A fontset font seems to be a font, which is used for a specific set of
;; characters, which can be associated with a particular language. Using fontset
;; font settings, it should be possible to set a font per langugage, as is
;; probably done on the Emacs HELLO page.

(let ((chinese-font "WenQuanYi Micro Hei Mono:weight=normal:height=140:antialias=1"))
  (dolist (charset '(kana han symbol cjk-misc bopomofo))
    (set-fontset-font "fontset-default"
                      charset
                      chinese-font)))
```
